﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SlidingPanel.Helpers;
using SlidingPanel.Library;
using SlidingPanel.Pages;

namespace SlidingPanel
{
    public partial class Shell
    {
        public Shell()
        {
            InitializeComponent();

            // RootFrame is set to the navigation frame, so it is accessible from anywhere
            NavigationHelper.Instance.Initialize(MainFrame);

            MainFrame.NavigationFailed += MainFrame_NavigationFailed;
            MainFrame.Navigating += MainFrame_Navigating;
        }

        void MainFrame_Navigating(object sender, NavigatingCancelEventArgs e)
        {
            // Every time we navigate, we animate to the center panel
            MainPanel.CurrentSide = Side.Center;
        }

        void MainFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
        }

        private void LeftPanelButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (MainPanel.CurrentSide != Side.Left)
                MainPanel.CurrentSide = Side.Left;
            else
                MainPanel.CurrentSide = Side.Center;
        }

        private void RightPanelButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (MainPanel.CurrentSide != Side.Right)
                MainPanel.CurrentSide = Side.Right;
            else
                MainPanel.CurrentSide = Side.Center;
        }
    }
}